package com.carl.zlds.controller.admin;

import com.carl.zlds.tool.common.result.Result;
import com.carl.zlds.annotation.Login;
import com.carl.zlds.controller.BaseController;
import com.carl.zlds.pojo.dto.SaveAdminDTO;
import com.carl.zlds.service.IAdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Map;

/**
 * @author carl
 */
@Slf4j
@RestController(value = "admin.adminController")
@RequestMapping("/admin/1/admin")
@Api(tags = {"管理端 - 管理员管理"})
public class AdminController extends BaseController {

    private final IAdminService adminService;

    @Autowired
    public AdminController(IAdminService adminService) {
        this.adminService = adminService;
    }

    @ApiOperation("登录")
    @PostMapping(value = "/login")
    @Login(needToken = false)
    public Result<Map<String, Object>> login(@Valid SaveAdminDTO dto) {
        Map<String, Object> map = adminService.login(dto);
        return Result.success(map);
    }

    @ApiOperation("登出")
    @PostMapping(value = "/logout")
    public Result<Void> delete(@RequestParam("token") String token) {
        adminService.logout(token);
        return Result.success();
    }
}
